package com.example.example.fragment;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.example.R;

import java.util.ArrayList;
import java.util.List;

/***
 * Created by Administrator on 2017/11/4.
 */

public class TwoFragment extends BaseFragment {

    private  ImageView imageView;
    private RecyclerView recyclerview ;


    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

        List<Integer> datas=new ArrayList<>();
        datas.add(R.mipmap.two_one);
        datas.add(R.mipmap.two_two);


        recyclerview=(RecyclerView) findViewById(R.id.recyclerview);
        //设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerview.setLayoutManager(linearLayoutManager);

        GalleryAdapter adapter=new GalleryAdapter(getActivity(),datas);
        recyclerview.setAdapter(adapter);

    }

    public ImageView getImageView() {
        return imageView;
    }

    @Override
    public int getFragmentViewById() {
        return R.layout.two_fragment;
    }

    public class GalleryAdapter extends
            RecyclerView.Adapter<GalleryAdapter.ViewHolder>
    {
        private LayoutInflater mInflater;
        private List<Integer> mDatas;

        public GalleryAdapter(Context context, List<Integer> datats)
        {
            mInflater = LayoutInflater.from(context);
            mDatas = datats;
        }

        public class ViewHolder extends RecyclerView.ViewHolder
        {
            public ViewHolder(View arg0)
            {
                super(arg0);
            }

            ImageView mImg;
            TextView mTxt;
        }

        @Override
        public int getItemCount()
        {
            return mDatas.size();
        }

        /**
         * 创建ViewHolder
         */
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i)
        {
            View view = mInflater.inflate(R.layout.two_item,
                    viewGroup, false);
            ViewHolder viewHolder = new ViewHolder(view);

            viewHolder.mImg = (ImageView) view.findViewById(R.id.img);
            return viewHolder;
        }

        /**
         * 设置值
         */
        @Override
        public void onBindViewHolder(final ViewHolder viewHolder, final int i)
        {
            viewHolder.mImg.setImageResource(mDatas.get(i));
        }

    }

}
